/*
 * Adaptable.java
 *
 * Created Oct 10, 2006
 * David Connell
 * Copyright (c) 2005 Synergy Systems, Inc
 */
package org.puresilk.afx.xmlbeans;

import org.jdom.Element;

/**
 * Generic base class for Adaptable beans. Default
 * implementation defines the wrapper api for XML
 * adaptable beans.  
 */
public class Adaptable implements XMLBean {
	private XMLBean bean = null;

	/** default constructor */
	public Adaptable(){}
		
	/** self loading constructor */
	public Adaptable(XMLBean bean){
		setBean(bean);
	}
	
	/** bean loader */
	public void setBean(XMLBean bean){
		this.bean = bean;
	}
	
	/** bean extractor */
	public XMLBean getBean() {
		return bean;
	}

	/* (non-Javadoc)
	 * @see org.puresilk.xmlbeans.XMLBean#from_xml(org.jdom.Element)
	 */
	public void from_xml(Element xml) {
		if (bean != null)
			bean.from_xml(xml);
	}

	/** use for serializing to an XML (sub)tree node */
	public Element to_xml() {
		// defaults to flat implementation
		return to_xml_node();
	}	

	/** use to serialize to a flat XML node (attributes only)*/
	public Element to_xml_node() {
		Element xml = null;
		if(bean != null)
			xml = bean.to_xml_node();
		return xml;
	}

}
